<template>
  <div>

	<myheader></myheader>

	<br /><br />

			<!--面包屑导航-->
			<Breadcrumb :datas="datas" ></Breadcrumb>

	

	<section class="featured-block text-center">
		<div class="container">

			<table>
					<tr >
						<td style="padding:5px;">
							
							商品名称:

						</td>
						<td style="padding:5px;">
							
							<input type="text" v-model="name" />

						</td>
					</tr>

					<tr>
						<td style="padding:5px;">
							
							商品简介:

						</td>
						<td style="padding:5px;">
							
							<input type="text" v-model="desc" />

						</td>
					</tr>

					<tr>
						<td style="padding:5px;">
							
							颜色:

						</td>
						<td style="padding:5px;">
							
							<input type="text" v-model="color" />

						</td>
					</tr>

          <tr>
            <td style="padding:5px;">
              
              号码:

            </td>
            <td style="padding:5px;">
              
              <input type="text" v-model="size" />

            </td>
          </tr>
		  
          <tr>
            <td style="padding:5px;">
              
              季节:

            </td>
            <td style="padding:5px;">
              
              <input type="text" v-model="season" />

            </td>
          </tr>
		   <tr>
            <td style="padding:5px;">
              
              商品标签:

            </td>
            <td style="padding:5px;">
              
              <input type="text" v-model="tags">

            </td>
          </tr>


					<tr>
						<td style="padding:5px;">
							
							价格:

						</td>
						<td style="padding:5px;">
							
							<input type="text" v-model="price" />

						</td>
					</tr>
					<tr>
            <td style="padding:5px;">
              
              商品演示视频:

            </td>
            <td style="padding:5px;">
              
              <input type="file" @change="upload"  />

            </td>
          </tr>


					<tr>
						<td style="padding:5px;">
							

						</td>
						<td style="padding:5px;">
							
							<Button @click="submit" color="green">提交</Button> &nbsp;&nbsp;

						</td>
					</tr>

			</table>
			
			

		</div>
	</section>
	

	
	
	
	<footer class="footer">

		<div class="container">
			@v3u.cn
		</div>
		
		
	</footer>
    
  </div>
  
</template>


 
<script>

//导包
import myheader from './myheader.vue';
import dragVerify from 'vue-drag-verify';
import {config,formatXml} from '../config.js';

export default {
  data () {
    return {
      msg: "这是一个变量",
      //声明面包屑变量
      datas:[{title:'首页',route:{name:'index'}},{title:'添加商品'}],
      name:'',
      desc:'',
      color:'',
      size:'',
      season:'',
      price:0,
      cate_id:1,
	  tags:'',
    }
  },
  //注册组件标签
  components:{
  		'myheader':myheader
  },
  mounted:function(){
 
  
  },
  methods:{
		//提交
		submit:function(){
		// 商品标签mongo添加
		this.axios.get('http://127.0.0.1:8000/inserttags/',{params:{
			'id':this.cate_id,
			'tags':this.tags
		}})

      //拼接商品规格
      var parms = {};
      parms['color'] = this.color;
      parms['size'] = this.size;
      parms['season'] = this.season;

      //格式化字符串
      parms = JSON.stringify(parms);

      console.log(parms);

      //从字符串转回json
      //parms = JSON.parse(parms);
      //console.log(parms);

      //发送请求
      this.axios.get('http://localhost:8000/insertgoods/',{params:{name:this.name,desc:this.desc,parms:parms,price:this.price,cate_id:this.cate_id}}).then((result) =>{

              console.log(result);

              this.$Message(result.data.message);

      });


	  },
	  //上传方法
	upload:function(e){

		//声明文件对象
		let file = e.target.files[0];
		//声明参数类型
		let param = new FormData();
		//添加文件
		param.append('file',file);
		//声明上传文件头部
		let config = {'Content-Type':'multipart/form-data'};

		//发送请求
		this.axios.post('http://localhost:8000/uploadfile/',param,config).then((result) =>{

			console.log(result);
			//动态赋值
			this.src = 'http://localhost:8000/static/upload/'+result.data.filename;
			this.mysrc = result.data.filename;

		});


	}

     
  }
}


</script>
 
<style>



</style>